package com.burstly.lib.component.networkcomponent.inmobi;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import com.burstly.lib.component.AbstractAdaptor;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.LayoutParametersResolver;
import com.burstly.lib.component.networkcomponent.ClickAwareWrapper;
import com.burstly.lib.util.LoggerExt;
import com.inmobi.androidsdk.IMAdInterstitial;
import com.inmobi.androidsdk.IMAdInterstitial.State;
import com.inmobi.androidsdk.IMAdInterstitialListener;
import com.inmobi.androidsdk.IMAdListener;
import com.inmobi.androidsdk.IMAdRequest;
import com.inmobi.androidsdk.IMAdRequest.ErrorCode;
import com.inmobi.androidsdk.IMAdView;
import com.inmobi.androidsdk.IMAdView.AnimationType;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.Map;

final class InmobiAdaptor extends AbstractAdaptor
{
  static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("inmobi", false);
  private static final String NETWORK_NAME = "inmobi";
  private static final String NOT_READY_MESSAGE = "Inmobi interstitial ad is not in READY state.";
  IMAdInterstitial mAdInterstitial;
  private final InmobiConfigurator mConfigurator;

  InmobiAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " InmobiAdaptor");
    this.mConfigurator = new InmobiConfigurator();
  }

  private View createBannerAd()
  {
    IMAdRequest localIMAdRequest = new IMAdRequest();
    this.mConfigurator.configure(localIMAdRequest);
    IMAdView localIMAdView = new IMAdView((Activity)getContext(), this.mConfigurator.getAdUnit(), this.mConfigurator.getAppId());
    localIMAdView.setAnimationType(IMAdView.AnimationType.ANIMATION_OFF);
    localIMAdView.setIMAdListener(new BannerInmobiListener(this));
    localIMAdView.setRefreshInterval(-1);
    localIMAdView.loadNewAd(localIMAdRequest);
    return wrapView(localIMAdView);
  }

  private void createInterstitialAd(boolean paramBoolean)
  {
    IMAdRequest localIMAdRequest = new IMAdRequest();
    this.mConfigurator.configure(localIMAdRequest);
    this.mAdInterstitial = new IMAdInterstitial((Activity)getContext(), this.mConfigurator.getAppId());
    this.mAdInterstitial.setIMAdInterstitialListener(new InterstitiaInmobiListener(this, paramBoolean));
    this.mAdInterstitial.loadNewAd(localIMAdRequest);
  }

  private FrameLayout wrapView(View paramView)
  {
    ClickAwareWrapper localClickAwareWrapper = new ClickAwareWrapper(getContext(), getAdaptorListener(), getViewId(), "inmobi");
    localClickAwareWrapper.addView(paramView, getLayoutParamsResolver().resolveParameters());
    return localClickAwareWrapper;
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    this.mConfigurator.initConfigurator(paramMap);
  }

  public void destroy()
  {
    super.destroy();
    this.mAdInterstitial = null;
  }

  protected View doGetNewAd()
  {
    LoggerExt localLoggerExt = LOG;
    String str = this.mTag;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.mConfigurator.getAppId();
    localLoggerExt.logInfo(str, "Inmobi appId: {0}", arrayOfObject);
    if (this.mConfigurator.isInterstitial())
    {
      createInterstitialAd(false);
      return null;
    }
    return createBannerAd();
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    if (this.mConfigurator.isInterstitial())
      return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public String getNetworkName()
  {
    return "inmobi";
  }

  public View precacheAd()
  {
    return getNewAd();
  }

  public void precacheInterstitialAd()
  {
    LoggerExt localLoggerExt = LOG;
    String str = this.mTag;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.mConfigurator.getAppId();
    localLoggerExt.logInfo(str, "Inmobi appId: {0}", arrayOfObject);
    createInterstitialAd(true);
  }

  public void showPrecachedInterstitialAd()
  {
    if (this.mAdInterstitial == null)
    {
      getAdaptorListener().failedToLoad("inmobi", this.mConfigurator.isInterstitial(), "Interstitial ad instance is null.");
      return;
    }
    if (!IMAdInterstitial.State.READY.equals(this.mAdInterstitial.getState()))
    {
      getAdaptorListener().failedToLoad("inmobi", this.mConfigurator.isInterstitial(), "Inmobi interstitial ad is not in READY state.");
      return;
    }
    this.mAdInterstitial.show();
    getAdaptorListener().didLoad("inmobi", this.mConfigurator.isInterstitial());
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  private static abstract class AbstractInmobiListener
  {
    final Reference<InmobiAdaptor> mAdaptor;
    private final boolean mIsInterstitial;

    AbstractInmobiListener(InmobiAdaptor paramInmobiAdaptor, boolean paramBoolean)
    {
      this.mAdaptor = new WeakReference(paramInmobiAdaptor);
      this.mIsInterstitial = paramBoolean;
    }

    protected void handleFailureCallback(IMAdRequest.ErrorCode paramErrorCode)
    {
      handleFailureCallback("Inmobi error code: " + paramErrorCode);
    }

    protected void handleFailureCallback(String paramString)
    {
      InmobiAdaptor localInmobiAdaptor = (InmobiAdaptor)this.mAdaptor.get();
      if ((localInmobiAdaptor != null) && (!localInmobiAdaptor.isStopped()))
      {
        InmobiAdaptor.LOG.logInfo(localInmobiAdaptor.mTag, "Failed to receive Inmobi...", new Object[0]);
        localInmobiAdaptor.getAdaptorListener().failedToLoad("inmobi", this.mIsInterstitial, paramString);
      }
    }

    protected void handleInterstitialState(boolean paramBoolean)
    {
      InmobiAdaptor localInmobiAdaptor = (InmobiAdaptor)this.mAdaptor.get();
      if ((localInmobiAdaptor != null) && (!localInmobiAdaptor.isStopped()))
      {
        if (paramBoolean)
          localInmobiAdaptor.getAdaptorListener().shownFullscreen(InmobiAdaptor.FULLSCREEN_INFO);
      }
      else
        return;
      localInmobiAdaptor.getAdaptorListener().dismissedFullscreen(InmobiAdaptor.FULLSCREEN_INFO);
    }

    protected void handleSuccessCallback()
    {
      InmobiAdaptor localInmobiAdaptor = (InmobiAdaptor)this.mAdaptor.get();
      if ((localInmobiAdaptor != null) && (!localInmobiAdaptor.isStopped()))
      {
        InmobiAdaptor.LOG.logInfo(localInmobiAdaptor.mTag, "Inmobi received...", new Object[0]);
        localInmobiAdaptor.getAdaptorListener().didLoad("inmobi", this.mIsInterstitial);
      }
    }

    protected void triggerClickEvent()
    {
      InmobiAdaptor localInmobiAdaptor = (InmobiAdaptor)this.mAdaptor.get();
      if ((localInmobiAdaptor != null) && (!localInmobiAdaptor.isStopped()))
        localInmobiAdaptor.getAdaptorListener().adWasClicked("inmobi", this.mIsInterstitial);
    }
  }

  private static class BannerInmobiListener extends InmobiAdaptor.AbstractInmobiListener
    implements IMAdListener
  {
    BannerInmobiListener(InmobiAdaptor paramInmobiAdaptor)
    {
      super(false);
    }

    public void onAdRequestCompleted(IMAdView paramIMAdView)
    {
      handleSuccessCallback();
    }

    public void onAdRequestFailed(IMAdView paramIMAdView, IMAdRequest.ErrorCode paramErrorCode)
    {
      handleFailureCallback(paramErrorCode);
    }

    public void onDismissAdScreen(IMAdView paramIMAdView)
    {
      handleInterstitialState(false);
    }

    public void onLeaveApplication(IMAdView paramIMAdView)
    {
    }

    public void onShowAdScreen(IMAdView paramIMAdView)
    {
      handleInterstitialState(true);
    }
  }

  private static class InterstitiaInmobiListener extends InmobiAdaptor.AbstractInmobiListener
    implements IMAdInterstitialListener
  {
    private final boolean mIsPrecacheRequest;

    InterstitiaInmobiListener(InmobiAdaptor paramInmobiAdaptor, boolean paramBoolean)
    {
      super(true);
      this.mIsPrecacheRequest = paramBoolean;
    }

    public void onAdRequestFailed(IMAdInterstitial paramIMAdInterstitial, IMAdRequest.ErrorCode paramErrorCode)
    {
      handleFailureCallback(paramErrorCode);
    }

    public void onAdRequestLoaded(IMAdInterstitial paramIMAdInterstitial)
    {
      if (!this.mIsPrecacheRequest)
      {
        if (!IMAdInterstitial.State.READY.equals(paramIMAdInterstitial.getState()))
        {
          handleFailureCallback("Inmobi interstitial ad is not in READY state.");
          return;
        }
        paramIMAdInterstitial.show();
      }
      handleSuccessCallback();
    }

    public void onDismissAdScreen(IMAdInterstitial paramIMAdInterstitial)
    {
      handleInterstitialState(false);
    }

    public void onLeaveApplication(IMAdInterstitial paramIMAdInterstitial)
    {
      triggerClickEvent();
    }

    public void onShowAdScreen(IMAdInterstitial paramIMAdInterstitial)
    {
      handleInterstitialState(true);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.inmobi.InmobiAdaptor
 * JD-Core Version:    0.6.2
 */